#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pygame, sys

# 初始化
pygame.init()
SCREEN = pygame.display.set_mode((400, 400))
pygame.display.set_caption('ASDW')
x = 110
y = 130

# 游戏主循环
while True: 
    for event in pygame.event.get():
        # 处理退出事件
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        # 键盘按下事件
        elif event.type == pygame.KEYDOWN:
            # 'a'键被按下
            if event.key == pygame.K_a:
                x -= 5
            elif event.key == pygame.K_d:
                x += 5
            elif event.key == pygame.K_s:
                y += 5
            elif event.key == pygame.K_w:
                y -= 5
    SCREEN.fill((255, 255, 255))
    # 调用 pygame.display.update() 方法更新整个屏幕的显示
    pygame.draw.rect(SCREEN, (255, 0, 0), (x, y, 50, 50))

    pygame.display.update()
    pygame.time.delay(50)